package com.tanhua.admin.controller;

import com.tanhua.admin.service.DashBoardService;
import com.tanhua.admin.vo.DashBoardVo;
import com.tanhua.admin.vo.DistributionVo;
import com.tanhua.admin.vo.SummaryVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;


/**
 * @ClassName DashBoardController
 * @Description TODO
 * @Author JavaDev
 * @Date 2021/1/16 20:05
 * @Version 1.0
 */
@RestController
@RequestMapping("/dashboard")
@Slf4j
public class DashBoardController {

    @Autowired
    private DashBoardService dashBoardService;

    /**
       * @Description:  新增、活跃用户、次日留存率
       * @Param:[sd, ed, type]
       * @return:org.springframework.http.ResponseEntity<java.lang.Void>
       * @Author:JinboYang
       * @Date:2021/1/17
       */
    @GetMapping("users")
    public ResponseEntity<DashBoardVo> dashBoardMsg(@RequestParam("sd") Long sd,
                                                    @RequestParam("ed") Long ed,
                                                    @RequestParam("type") Integer type){
        try {
            DashBoardVo dashBoardVo = this.dashBoardService.dashBoardMsg(sd,ed,type);
            if(dashBoardVo!=null){
                return ResponseEntity.ok(dashBoardVo);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
    }


    /**
       * @Description: 总计
       * @Param:[]
       * @return:org.springframework.http.ResponseEntity
       * @Author:JinboYang
       * @Date:2021/1/18
       */
    @GetMapping("summary")
    public ResponseEntity<SummaryVo> querySummaryData(){
        try {
            SummaryVo summaryVo = this.dashBoardService.querySummaryData();
            if (summaryVo != null){
                return ResponseEntity.ok(summaryVo);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
    }

    /**
       * @Description: 注册用户分布，行业top、年龄、性别、地区
       * @Param:[startDate, endDate]
       * @return:org.springframework.http.ResponseEntity<DistributionVo>
       * @Author:JinboYang
       * @Date:2021/1/18
       */
    @GetMapping("distribution")
    public ResponseEntity<DistributionVo> queryDistributionData(@RequestParam("sd") Long startDate,
                                                                @RequestParam("ed") Long endDate){

        try {
            DistributionVo distributionVo = this.dashBoardService.queryDistributionData(startDate, endDate);
            if (distributionVo != null){
                return ResponseEntity.ok(distributionVo);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
    }
}

